using System;
using System.Collections.Generic;

namespace CSW.Framework.Common
{
    /// <summary>
    /// Error message.
    /// </summary>
    public class ErrorMessage
    {
        private readonly List<string> m_ErrorMessage = new List<string>();

        /// <summary>
        /// Appends the specified error message.
        /// </summary>
        /// <param name="errorMessage">The error message.</param>
        public void Append(string errorMessage)
        {
            Guard.ArgumentNotNullOrEmptyString(errorMessage, "errorMessage");

            m_ErrorMessage.Add(errorMessage);
        }

        /// <summary>
        /// Gets a value indicating whether this instance has errors.
        /// </summary>
        /// <value><c>true</c> if this instance has errors; otherwise, <c>false</c>.</value>
        public bool HasErrors
        {
            get { return (m_ErrorMessage.Count > 0); }
        }

        /// <summary>
        /// Gets the error messages.
        /// </summary>
        /// <value>The error messages.</value>
        public IEnumerable<string> ErrorMessages
        {
            get { return m_ErrorMessage; }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"></see> that represents the current list of errors.
        /// </summary>
        /// <returns>A <see cref="T:System.String"></see> that represents the current list of errors..</returns>
        public override string ToString()
        {
            string fullErrorMessage = string.Empty;
            foreach (string errorMessage in m_ErrorMessage)
            {
                if (!string.IsNullOrEmpty(fullErrorMessage))
                    fullErrorMessage += Environment.NewLine;

                fullErrorMessage += errorMessage;
            }
            return fullErrorMessage;
        }
    }
}